package day1

import org.apache.spark.{SparkConf, SparkContext}

object Text2 {
  def main(args: Array[String]): Unit = {

    //1.创建SparkContext
    val sparkConf: SparkConf = new SparkConf().setMaster("spark://hadoop10:7077").setAppName("SparkWordCount")
    val sc = new SparkContext(sparkConf)

    //2.读取文件内容，执行SparkRDD任务
    sc.textFile("hdfs://hadoop10:9000/a.txt")
      .flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(_._1)
      .map(t => (t._1, t._2.size))
      .saveAsTextFile("hdfs://hadoop10:9000/results")

    //3.关闭SparkContext
    sc.stop()
  }
}
